package com.ywk.pattern._21_singleton._21_4;

import java.io.ObjectStreamException;
import java.io.Serializable;

//懒汉式，线程不安全
public class Singleton implements Serializable {
    private static Singleton instance;

    private Singleton() {
    }

    public static Singleton getInstance() {
        if (instance == null) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            instance = new Singleton();
        }
        return instance;
    }
    private Object readResolve() throws ObjectStreamException {
        return instance;
    }
}
